<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<style>
			.register_btn>button{
				height: 40px;
				width: 100%;
				background-color: #9C005E;
				color: #FFFFFF;
				border: 1px solid #9C005E;
				margin-left: 0px;
				display: block;
				transition: margin-left 1s;
			}
			#register,#next{
				width: 100%;
				height: 60px;
				padding: 10px;
			}
			.mui-input-row input{
				color: #666666;
			}
			.mui-input-group textarea {
				font-size: 14px;
				height: 100%;
				line-height: 20px;
				display: block;
			}
			.mui-input-group #clear{
				min-height: 40px;
			}
			h5{
				font-size: 14px;
				color: #000000;
				padding-left: 4px;
			}
		</style>
		<link rel="stylesheet" href="../library/css/mui.picker.min.css" />
		<link rel="stylesheet" href="../library/css/uphoto.css" />
	</head>

	<body>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery.min.js" ></script>
		<script type="text/javascript" src="../library/js/formjs.js" ></script>
		<script type="text/javascript" src="../library/js/city.data-3.js" ></script>
		<script type="text/javascript" src="../library/js/mui.picker.min.js" ></script>
		<script type="text/javascript" src="../js/Strings.js" ></script>
		<script type="text/javascript" src="../js/evalHttp.js" ></script>
		<script type="text/javascript" src="../library/js/uphoto.js" ></script>
		<script type="text/javascript">
			mui.init();
		</script>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">发布转让</h1>
		</header>
		<div class="mui-content">
			<div class="mui-input-group mui-content-padded">
				<div class="mui-input-row">
					<label>商品品牌</label>
					<input type="text"  placeholder="请输入商品品牌" id="ppai" class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row">
					<label>型号规格</label>
					<input type="text" placeholder="请输入产品型号规格" id="xhao" class="mui-input mui-input-clear"/>
				</div>
				<div class="mui-input-row" >
					<label>出厂地</label>
					<input type="text" placeholder="请输入商品出场地" id="cdi" class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>所在地区</label>
					<input type="text" placeholder="请输入商品所在地区" id="dqu" class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>转让数量 </label>
					<input type="number" placeholder="请输入转让数量" id="sliang" class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>设备原价 </label>
					<input type="number" placeholder="请输入产品原价" id="jge" class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>商品名称</label>
					<input type="text" placeholder="请输入产品类别" id="lbie" class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>商品重量</label>
					<input type="text" placeholder="请输入商品重量" id="zliang" class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>有效期</label>
					<input type="text" placeholder="请输入商品有效期" id="yxq" class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>使用时长</label>
					<input type="text" placeholder="请输入商品使用时长" id="schang"  class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>时长单位</label>
					<input type="text" placeholder="请输入时长单位" id="dwei"  class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row" >
					<label>转让价格</label>
					<input type="number" placeholder="请输入转让价格" id="zrjg"  class="mui-input mui-input-clear" />
				</div>
				<div class="mui-input-row mui-checkbox mui-right">
					<label>提供发票</label>
					<input name="checkbox" value="Item 1" type="checkbox">
				</div>
				<div class="mui-content-padded">
					<h5>设备描述</h5>
					<div class="row mui-input-row" id="clear">
						<textarea id='mshu' class="mui-input-clear question" placeholder="请详细描述..." ></textarea>
					</div>
				</div>
				<div class="mui-content-padded">
					<h5>使用步骤</h5>
					<div class="row mui-input-row">
						<textarea id='bzou' class="mui-input-clear question" placeholder="请输入使用步骤说明..." ></textarea>
					</div>
				</div>
				<div class="mui-content-padded">
					<h5>注意事项</h5>
					<div class="row mui-input-row" id="clear">
						<textarea id='sxiang' class="mui-input-clear question" placeholder="请输入注意事项" ></textarea>
					</div>
				</div>
				<div class="mui-content-padded">
					<h5>售后服务</h5>
					<div class="row mui-input-row" id="clear">
						<textarea id='fwu' class="mui-input-clear question" placeholder="请输入售后服务..." ></textarea>
					</div>
				</div>
				<div class="mui-content-padded">
					<h5>图片(大小1M以下,大于1M,自动压缩文档)</h5>
					<div class="pro">
						<progress value="0" max="100" id="imgSeek"></progress>
						<div>
							图片上传进度：
							<span class="protxt">0%</span>
						</div>
					</div>
					<ul id='image-list' class="row image-list">
						<li class="add">
								<label>+</label>
						</li>
					</ul>
				</div>
				<div class="mui-input-row register_btn" id="register">
					<button id="btn">提交</button>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			mui.plusReady(function(){
				var self = plus.webview.currentWebview();
				var val = Strings.indexData.index.lease.updataRegs;
				var data_op = self.data_op;
				var data_data = self.data_data;
				var JoinData = {
					fpiao:0
				};
				getAllSeek();
				var cityPicker = new mui.PopPicker({layer: 3});
				var seekPicker = new mui.PopPicker({layer: 2});
				var seekOptions = [];
				var pickerOptions = cityData3;
					//高中（包括：高中，职高，中专，技校），大专（大学学专科），大本（大学本科），硕士（硕士研究生），博士（博士研究生）
				mui(".mui-input-row").on("tap","input,button",function(e){
					var thisId = e.target.getAttribute("id");
					var slef = this;
					cityPicker.blur;
					seekPicker.blur;
					switch(thisId){
						case "dqu":{
							cityPicker.setData(pickerOptions)
							cityPicker.show(function(item) {
								inputText(item,slef,3)
							});
						};break;
						case "lbie":{
							leibie();
						};break;
						case "btn":{
							postData(slef);
						};break;
						default:{

						};break;
					}
					e.stopPropagation();
				})
				function inputText(SelectedItem,self,num){
						var that;
						if(typeof(self)=="string"){
							that = document.getElementById(self);
						}else{
							that = self;
						}
						var text = SelectedItem[0].text;
						var val = SelectedItem[0].value;
						if(num==2){
							text+="-"+SelectedItem[1].text;
							val +="-"+SelectedItem[1].value;
						}
						if(num==3){
							text+="-"+SelectedItem[1].text;
							val +="-"+SelectedItem[1].value;
							text+="-"+SelectedItem[2].text;
							val +="-"+SelectedItem[2].value;
						}
						that.value = text;
						that.setAttribute("data-value",val);
					}
				function postData(e){
					if(getNewData()){
						var slef = e;
						slef.setAttribute("disabled","disabled");
						slef.innerHTML = "正在提交您的信息..";
						console.log(JSON.stringify(JoinData));
						Xeval.Http(Xeval.Mode.HTTP_POST_ZHUANR,JoinData,function(isOk,data){
							slef.removeAttribute("disabled");
							slef.innerHTML = "提交";
							if(isOk){
								mui.alert(data.msg,val.title,val.btnValue);
								if(data.state==1){
									setTimeout(function(){
										mui.back();
									},18)
								}
							}else{
								mui.confirm(val.postError,val.title,val.postBtn,function(e){
									eLog.l(e.index);
									if(e.index==0){
										postData(self);
									}
								});
							}
						},true);
					}else{
					}
				}
				mui('.mui-input-group').on('change', 'input', function() {
					var value = this.checked?"1":"0";
					JoinData.fpiao = value;
				});
				function getNewData(){
					JoinData.ppai = mui("#ppai")[0].value;
					JoinData.xhao = mui("#xhao")[0].value;
					JoinData.dqu = $("#dqu").attr("data-value");
					JoinData.sliang = mui("#sliang")[0].value;
					JoinData.jge = mui("#jge")[0].value;
					JoinData.lbie = $("#lbie").attr("data-value");
					JoinData.zliang = mui("#zliang")[0].value;
					JoinData.yxq = mui("#yxq")[0].value;
					JoinData.schang = mui("#schang")[0].value;
					JoinData.dwei = mui("#dwei")[0].value;
					JoinData.mshu = mui("#mshu")[0].value;
					JoinData.bzou = mui("#bzou")[0].value;
					JoinData.sxiang = mui("#sxiang")[0].value;
					JoinData.fwu = mui("#fwu")[0].value;
					JoinData.zrjg = mui("#zrjg")[0].value;
					JoinData.cdi = mui("#cdi")[0].value;
					for(var item in JoinData){
						var value_ = JoinData[item];
						if(value_.trim()=="" || value_==null){
							mui.alert(val[item].msg);
							return false;
						}else{//表单正则验证
							var regx = val[item];
							var regxJson = new Object(regx);
							var reg = regxJson.reg;
							if(reg!=null && typeof(reg)!="undefined"){
								if(!reg.test(value_)){
									mui.alert(regxJson.msg);
									return false;
								}
							}
						}
					}
					var imgstr = [];
					var imgs = $("#image-list .imgbox");
					var dq = JoinData.dqu;
					var lb = JoinData.lbie;
					var diqus = dq.split("-");
					var leibies = lb.split("-");
					imgs.each(function(){
						imgstr.push($(this).attr("data-id"));
					})
					JoinData.imgs = imgstr.join(",");
					if(imgstr==""){
						alert("请上传图片");
						return false;
					}else{
						var upData = {
							pd_brand:JoinData.ppai, 
							pd_kind1:leibies[1],
							pd_kind:leibies[0], 
							pd_model:JoinData.xhao,
							pd_place:JoinData.cdi,
							pd_province:diqus[0], 
							pd_city:diqus[1], 
							pd_district:diqus[2], 
							pd_price:JoinData.jge,//（价格）, 
							pd_stock:JoinData.sliang,//（库存）, 
							pd_weight:JoinData.zliang,//（重量）, 
							pd_instruction:JoinData.mshu,//（使用说明）, 
							pd_validdate:JoinData.yxq,//（发布有效期/天）, 
							pd_rentstxt:JoinData.bzou,//（租用说明）, 
							pd_annouce:JoinData.sxiang,//（注意事项）,
							pd_term:JoinData.schang,//（使用时常）,
							pd_unit:JoinData.dwei,//（使用时间的单位年/天）,
							pd_notes:JoinData.fwu,//（售后）, s
							Rents_picture:JoinData.imgs,//（图片id））
							pd_invoice:JoinData.fpiao,
							pd_vipprice:JoinData.zrjg
						};
					JoinData = upData;
					}
						return true;
					}
			function leibie(data){
				if(seekOptions.length==0){
					getAllSeek();
				}else{
					seekPicker.setData(seekOptions)
					seekPicker.show(function(item){
						inputText(item,"lbie",2);
					});
				}
			}
			function getAllSeek() {
				var clientNum = 0;
				var http = function() {
					Xeval.setUrl("http://139.196.113.126/");
					Xeval.Http(Xeval.Mode.HTTP_GET_LEASE_GET_SEEK, {}, seekListener, true)
					Xeval.setUrl("http://139.224.164.193/");
				};
				http();
				function seekListener(isOk, data) {
					if(isOk) {
						seekOptions = formarSeek(data);
					} else {
						if(clientNum<3){
							clientNum++;
							setTimeout(http,1000);
						}else{
							mui.alert("网络错误,请检查您的网络环境！");
						}
					}
				}
			}
			function formarSeek(data){
		  		var jsonc = [],jsonp = [];
					data.forEach(function(item){
						if(item.rt_kind==0){
							jsonp.push(item);
						}else{
							jsonc.push(item);
						}
					})
					var result = [];
					jsonp.forEach(function(itemp,i){
						var pid = itemp.rt_code;
						jsonp[i].children = [];
						var sl = {};
						sl.text = jsonp[i].rt_name;
						sl.value = jsonp[i].rt_code;
						sl.children  = [];
						jsonc.forEach(function(itemc,j){
							if(itemc.rt_parent==pid){
								var cd = {};
								cd.text = itemc.rt_name;
								cd.value = itemc.rt_code;
								sl.children.push(cd);
							}
						})
						result.push(sl);
					})
					return result;
				}
			})
			
		</script>
	</body>

</html>